package com.wenhai.leetcode.set;

import java.util.TreeSet;

/**
 * https://leetcode-cn.com/problems/unique-morse-code-words/
 *
 * @ClassName _804唯一摩尔斯密码词
 * @Description
 * @Author 谢文海
 * @Date 2021/3/7 18:25
 * @Version 1.0
 **/
public class _804唯一摩尔斯密码词 {

    public int uniqueMorseRepresentations(String[] words) {
        String[] codes = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        TreeSet<String> set = new TreeSet<>();

        for (String word : words) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                sb.append(codes[word.charAt(i) - 'a']);
            }
            set.add(sb.toString());
        }
        return set.size();
    }


}
